package com.bytedance.improvingroad.scroll_conflict

import android.content.Context
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.widget.ListView
import androidx.core.view.get
import androidx.viewpager.widget.PagerAdapter
import com.bytedance.improvingroad.R
import com.bytedance.improvingroad.adapter.RootListAdapter
import com.bytedance.improvingroad.utils.Utils

/**
 * Created by chenxiong
 * date 12/21/21
 */
class MyPagerAdapter(private val context: Context): PagerAdapter() {

    override fun getCount(): Int {
        return 5
    }

    override fun instantiateItem(container: ViewGroup, position: Int): Any {
        val view = LayoutInflater.from(context).inflate(R.layout.conflict_item_list,container,false)
        val list = view.findViewById<ListView>(R.id.myList)
        list.adapter = RootListAdapter(Utils.getMutableData())
        container.addView(view)
        return view
    }

    override fun destroyItem(container: ViewGroup, position: Int, `object`: Any) {
        container.removeView(`object` as View)
    }

    override fun isViewFromObject(view: View, `object`: Any): Boolean {
        return view == `object`
    }
}